home *** CD-ROM | disk | FTP | other *** search
- /* Version B */
-
- /*===========================================================\
- | UltraShell (tm) |
- | |
- | cmp.c |
- | This program performs a binary comparison of two files, |
- | and returns a value of 0 to indicate that they are |
- | the same. If identical, it also prints "same" |
- | to stdout; if not, it prints "different". |
- | from UltraShell. |
- | |
- | Copyright (C) 1994 by Zack T. Smith |
- | |
- | Permission is granted to freely distribute this |
- | file. The data contained herein may be adapted to |
- | whatever tasks are at hand, so long as they |
- | involve the use of UltraShell. |
- \===========================================================*/
-
-
- #include <stdio.h>
-
- #include "ucommand.h"
-
-
-
- main ()
- {
- char *argv[100];
- int ch, ch2;
- FILE *f1, *f2;
- int same = 1;
- long argc;
-
- if (!(argc = ucommand (argv, 100)))
- {
- printf ("No shell information found.\n");
- shell_exit (2);
- }
-
- /* Usage for 'cmp' is 'cmp file1 file2'
- * Here we verify that we have 3 args.
- */
- if (argc != 3)
- shell_exit (4);
-
- f1 = fopen (argv[1], "r");
- if (!f1)
- {
- fprintf (shell_stderr, "Unable to open %s.\n", argv[1]);
- shell_exit (5);
- }
-
- f2 = fopen (argv[2], "r");
- if (!f2)
- {
- fprintf (shell_stderr, "Unable to open %s.\n", argv[2]);
- shell_exit (5);
- }
-
- do
- {
- ch = fgetc (f1);
- ch2 = fgetc (f2);
-
- if (ch != ch2)
- {
- same = 0;
- break;
- }
-
- if (ch == EOF)
- break;
- }
- while(1);
-
- if (same)
- {
- fprintf (shell_stdout, "same\n");
- shell_exit (0);
- }
- else
- {
- fprintf (shell_stdout, "different\n");
- shell_exit (1);
- }
- }
-
-
-